<?php

namespace common\models\searchs;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\SysUsers;

/**
 * SearchSysUsers represents the model behind the search form about `common\models\SysUsers`.
 */
class SearchSysUsers extends SysUsers
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'parent_id', 'type', 'role', 'last_login_time', 'reg_time', 'status','ours'], 'integer'],
            [['phone', 'parent_phone', 'password', 'truename', 'qq', 'qq_openid', 'email', 'weixin', 'wx_openid', 'tel', 'company_name', 'company_addr', 'company_regnum', 'company_range', 'company_spec_range', 'company_type', 'company_est_time', 'company_licence','audit'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = SysUsers::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'parent_id' => $this->parent_id,
            'type' => $this->type,
            'role' => $this->role,
            'last_login_time' => $this->last_login_time,
            'reg_time' => $this->reg_time,
            'status' => $this->status,
             'ours' => $this->ours,
        ]);

        $query->andFilterWhere(['like', 'phone', $this->phone])
            ->andFilterWhere(['like', 'parent_phone', $this->parent_phone])
            ->andFilterWhere(['like', 'password', $this->password])
            ->andFilterWhere(['like', 'truename', $this->truename])
            ->andFilterWhere(['like', 'qq', $this->qq])
            ->andFilterWhere(['like', 'qq_openid', $this->qq_openid])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'weixin', $this->weixin])
            ->andFilterWhere(['like', 'wx_openid', $this->wx_openid])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'company_name', $this->company_name])
            ->andFilterWhere(['like', 'company_addr', $this->company_addr])
            ->andFilterWhere(['like', 'company_regnum', $this->company_regnum])
            ->andFilterWhere(['like', 'company_range', $this->company_range])
            ->andFilterWhere(['like', 'company_spec_range', $this->company_spec_range])
            ->andFilterWhere(['like', 'company_type', $this->company_type])
            ->andFilterWhere(['like', 'company_est_time', $this->company_est_time])
            ->andFilterWhere(['like', 'company_licence', $this->company_licence]);

        return $dataProvider;
    }
}
